package com.atcumt.meituan;

import java.util.Scanner;

public class Main02 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // int num = scanner.nextInt();
        long num = scanner.nextLong();
        for (int i = 2; i <= 16; i++) {
            String s = converse(i, num);
            boolean flag = isPalindrame(s);
            if (flag) {
                System.out.println(i);
            }
        }
    }

    private static boolean isPalindrame(String s) {
        StringBuffer sb = new StringBuffer(s);
        sb.reverse();
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == sb.charAt(i)) {
                count++;
            }
        }
        if (count == s.length()) {
            return true;
        } else {
            return false;
        }   
    }

    private static String converse(int n, Long num) {
        String str = "";
        long rest;
        long shang = num;
        while (shang > 0) {
            rest = shang % n;
            shang = shang / n;

            if (rest > 9) {
                str = (char) ('a' + (rest - 10)) + str;
            } else {
                str = rest + str;
            }
        }
        return str;
    }
}
